﻿using Omabar.BLL;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Omabar.CMS.CMS
{
    public partial class CustomizedTravelList : System.Web.UI.Page
    {
        protected List<CUSTOMIZEDTRAVEL> cTravels;
        protected int pageCount;
        protected int pageNo = 1;
        protected int groupNo = 1;
        protected int groupCount = 1;
        protected string keywords;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pageNo = string.IsNullOrEmpty(Request["pageno"]) ? 1 : int.Parse(Request["pageno"]);

                CustomizedTravel_BLL bll = new CustomizedTravel_BLL();
                keywords = Request["keywords"];
                string sqllist = "select Top 10 CT_ID,DESTINATION,STARTCITY,TRAVELDAYS,ADULT,CHILD,BUDGET,STARTDATE,THEMES,HOBBYS,ADDITIONAL,USERNAME,USERID,TELEPHONE,EMAIL from (select row_number() over(order by CT_ID desc) as rownumber,* from CUSTOMIZEDTRAVEL {0}) A where rownumber > {1}";
                string sqlcount = "select count(*) from CUSTOMIZEDTRAVEL";
                if (!string.IsNullOrEmpty(keywords))
                {
                    string filter = string.Format(" where USERNAME like '%{0}%' OR TELEPHONE='{1}'", keywords, keywords);
                    sqlcount += filter;
                    sqllist = string.Format(sqllist, filter, (pageNo - 1) * 10);
                }

                sqllist = string.Format(sqllist, keywords, (pageNo - 1) * 10);
                cTravels = bll.GetModels(sqllist);

                if (cTravels == null) cTravels = new List<CUSTOMIZEDTRAVEL>();

                #region 计算分页
                int total = bll.GetCount(sqlcount);
                pageCount = total % 10 == 0 ? total / 10 : total / 10 + 1;
                groupNo = pageNo % 10 == 0 ? pageNo / 10 : pageNo / 10 + 1;
                groupCount = pageCount % 10 == 0 ? pageCount / 10 : pageCount / 10 + 1;
                #endregion
            }
        }
    }
}